<template>
	<view class="container">
		<view class="item-box">
			<view class="item-title">
				<view class="shop-ico"><image lazy-load="true"  src="../../static/images/shop-ico.png" class="shop-ico"></image></view>
				<view class="shop-name">{{goods.store.name}}</view>
			</view>
			<view class="item" @click="checkImg()">
				<view class="item-info">
					<!-- <view class="check-box">
						<view class="check-img">
							<image lazy-load="true"  src="../../static/images/check-1.png" class="check-img" v-if="checked"></image>
						</view>
						<view class="check-img">
							<image lazy-load="true"  src="../../static/images/check-2.png" class="check-img" v-if="!checked"></image>
						</view>
					</view> -->
					<view class="item-img">
						<image lazy-load="true"  :src="goods.thumbnail" mode="aspectFill" class="good-img"></image>
					</view>
					<view class="item-text">
						<view class="title">{{goods.name}}</view>
						<view class="type">
							<view>规格</view>
							<view class="size">{{goods.spec}}</view>
						</view>
						<view class="price-amount">
							<view class="price">￥{{goods.real_price}}</view>
							<view class="amount">
								<view class="reduce" @click="cutNum">-</view>
								<view class="item-num">{{goods_num}}</view>
								<view class="add" @click="addNum">+</view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		
		<view class="empty"></view>
		<view class="submit-menu">
			<view class="text-box">
				<!-- <view class="image-box">
					<view class="check-all" @click="checkAll()">
						<image lazy-load="true"  src="../../static/images/check-1.png" v-if="checkAllSta" class="check-all"></image>
						<image lazy-load="true"  src="../../static/images/check-2.png" v-if="!checkAllSta" class="check-all"></image>
					</view>
				</view>
				<view class="check-text">
					<view class="all">全选</view>
					<view class="delete">删除</view>
				</view> -->
				<view class="total-price">
					<view class="total">合计：</view>
					<view class="price">￥{{count_money}}</view>
				</view>
			</view>	
			<view class="submit-btn" @click="goOrder">提交</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				"checked":true,
				"checkAllSta":false,
				"store_sku_id":0,
				"goods_num":1,
				"real_price":0,
				"goods":{},
				"count_money":0
			}
		},
		onLoad(e) {
			var self = this;
			this.store_sku_id = e.id;
			this.goods_num = e.num || 1;
			this.count_money = parseFloat(this.real_price) * parseInt(this.goods_num);
			this.getGoodsData();
			// #ifdef H5
			let share_time_line={
				title:self.$request.h5_share_name, // 分享标题
				link: self.$request.h5_share_url+'?page=index', // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
				imgUrl: self.$request.h5_img_url+'/static/images/logo.png', // 分享图标
			}
			let share_app_message={
				title: self.$request.h5_share_name, // 分享标题
				desc: '我发现了一个很不错的商城，买家具有超大实惠！', // 分享描述
				link: self.$request.h5_share_url+'?page=index', // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
				imgUrl: self.$request.h5_img_url+'/static/images/logo.png', // 分享图标
			}
			uni.setStorageSync('share_time_line',share_time_line);
			uni.setStorageSync('share_app_message',share_app_message);
			self.$request.wx_config()
			// #endif
		},
		onShareAppMessage(res) {
		    if (res.from === 'button') {
		      console.log(res.target)
		    }
		    return {
		      title: this.$request.share_title,
		      path: '/pages/index/index'
		    }
		  },
		methods: {
			checkImg(){
				this.checked = !this.checked
			},
			checkAll(){
				this.checkAllSta = !this.checkAllSta
			},
			goOrder(){
				uni.redirectTo({
				    url: '../order/order?id='+this.store_sku_id+'&num='+this.goods_num
				});
			},
			getGoodsData(){
				var self = this;
				this.$request.request({
					url:'/goods/detail',
					data:{
						store_sku_id:this.store_sku_id
					},
					success:function(res){
						if(res.code==200){
							var x = res.result;
							console.log(x)
							x.detail = JSON.parse(x.detail);
							x.image = JSON.parse(x.image);
							x.detail.forEach((item,index)=>{
								x.detail[index] =self.$http_img(item);
							});
							x.spec_list.forEach((item,index)=>{
								x.spec_list[index].checked =false;
							});
							x.image.forEach((item,index)=>{
								x.image[index] =self.$http_img(item);
							});
							x.thumbnail =self.$http_img(x.thumbnail);
							x.price =self.$money(x.price);
							x.real_price =self.$money(x.real_price);
							x.store.logo =self.$http_img(x.store.logo);
							self.goods = x;
							self.real_price=x.real_price;
							self.count_money = parseFloat(self.real_price) * parseInt(self.goods_num);
						}else{
							
						}
					}
				})
			},
			addNum(){
				this.goods_num++;
				this.count_money = parseFloat(this.real_price) * parseInt(this.goods_num);
			},
			cutNum(){
				if(this.goods_num>1){
					this.goods_num--;
					this.count_money = parseFloat(this.real_price) * parseInt(this.goods_num);
				}
			}
		}
	}
</script>

<style>
	@import url("shopping-cart.css");
</style>
